package com.shujia.zookeeper;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;

public class Code04DeleteNode {
    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {

        ZooKeeper zooKeeper = new ZooKeeper("master:2181,node1:2181,node2:2181"
                , 10 * 1000
                , new Watcher() {
            @Override
            // 该方法在Zookeeper连接中会被触发两次，一次在建立连接时，另外一次在关闭连接时
            // 该方法执行时，是按照异步执行
            public void process(WatchedEvent event) {
                System.out.println("当前Zookeeper连接被触发...");
            }
        }
        );

        // 删除操作 要求节点不为空
        zooKeeper.delete("/api",-1);

        // 作业：编写一个函数要求完成迭代删除节点

        zooKeeper.close();

    }
}
